package com.lotus.lqmp.service.common.utils;

import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Date;

/**
 * description
 * @author Shiheng.Liu1
 * @since 2022/01/14 09:18
 */
public class CommonUtil {

    public static void setResponseExportParam(HttpServletResponse response, String fileName){
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
    }

    public static void setResponseExportZipParam(HttpServletResponse response, String fileName)
        throws UnsupportedEncodingException {
        String zipFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
        response.setContentType("application/x-msdownload");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + zipFileName + ".zip");
    }

    public static long covert2TimeStamp(Date time){
        return time == null ? 0L : time.getTime();
    }

}
